/**
 * 
 */
package com.hanhai.zrb.mobile.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hanhai.zrb.api.client.facade.MessageFacade;
import com.hanhai.zrb.api.client.result.MessageResult;
import com.hanhai.zrb.mobile.result.BaseApiResult;
import com.hanhai.zrb.mobile.util.FrontLoginUtil;
import com.hanhai.zrb.model.common.BaseUser;

@RequestMapping("/message")
@RestController
public class MessageApiController {

	@Resource
	private MessageFacade messageFacade;
	
	/**
	 * 站内消息已读回执
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping("/readMessage")
	public BaseApiResult readMessage(Long id){
		BaseApiResult result = new BaseApiResult();
		BaseUser loginUser = FrontLoginUtil.getCurrentUser();
		if(null==loginUser){
			result.setRes(0);
			result.setMsg("请先登录");
		}else{
			MessageResult messageResult = this.messageFacade.readMessage(loginUser.getUid(), id);	
			result.setRes(1);
			result.setData(messageResult.isSuccess());
		}
		return result;
	}
	
	@RequestMapping("/queryMessage")
	public BaseApiResult queryUserMessage(Long maxId,Integer limit,Integer read){
		if(maxId == null){
			maxId = Long.MAX_VALUE;
		}
		if(limit == null||limit<=0){
			limit = 10;
		}
		BaseApiResult result = new BaseApiResult();
		BaseUser loginUser = FrontLoginUtil.getCurrentUser();
		if(null==loginUser){
			result.setRes(0);
			result.setMsg("请先登录");
		}else{
			MessageResult messageResult = this.messageFacade.queryReceiveMessageByMaxId(loginUser.getUid(), read, maxId, limit);		
			result.setRes(1);
			result.setData(messageResult.getReceiveList());
		}
		return result;
	}
}
